﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using QLXuongCNTT.Object;
namespace QLXuongCNTT.DataLayers
{
    class dtlPhieuDeNghi
    {
          ConnectDB conn;
        SqlCommand cmd;
        string error;

        public string Error
        {
            get { return error; }
            set { error = value; }
        }
        public dtlPhieuDeNghi()
        {
            conn = new ConnectDB();
            error = "";
        }
        public DataTable getPhieuDeNghi(int Nam)
        {
            error = "";
            string sql = "Select * from PHIEUDENGHI WHERE YEAR(NGAY)="+Nam;
            cmd = new SqlCommand();
            cmd.CommandText = sql;
            conn.GetData(cmd);
            error = conn.Error;
            return conn;
        }
        public DataTable getPhieuDeNghi_sophieu(string sophieu)
        {
            error = "";
            string sql = "Select * from PHIEUDENGHI WHERE sophieu='" + sophieu + "'";
            cmd = new SqlCommand();
            cmd.CommandText = sql;
            conn.GetData(cmd);
            error = conn.Error;
            return conn;
        }
        public DataTable getPDN_nam()
        {
            error = "";
            string sql = "Select distinct year(NGAY) from PHIEUDENGHI";
            cmd = new SqlCommand();
            cmd.CommandText = sql;
            conn.GetData(cmd);
            error = conn.Error;
            return conn;
        }
        public void insertpdn(objPhieuDeNghi PDN)
        {
            error = "";
            string sql = "Insert into phieudenghi values('";
            sql += PDN.Sophieu + "','";
            sql += PDN.Ngay + "','";
            sql += PDN.Magv + "',N'";
            sql += PDN.Lydo + "','";
            sql += PDN.Tungay+ "','";
            sql += PDN.Denngay + "')";
            cmd = new SqlCommand();
            cmd.CommandText = sql;
            int rs = conn.Executive(cmd);
            if (rs <= 0)
                error = conn.Error;
        }
        public void DeletePDN(string sophieu)
        {
            error = "";
            string sql = "Delete from PHIEUDENGHI where SOPHIEU ='" + sophieu+ "'";
            cmd = new SqlCommand();
            cmd.CommandText = sql;
            conn.Executive(cmd);
            error = conn.Error;
        }
        public void UpdatePDN(objPhieuDeNghi PDN)
        {
            error = "";
            string sql = "Update Phieunhap set Ngay='";
            sql += PDN.Ngay + "',magv ='";
            sql += PDN.Magv + "', lydo =N'";
            sql += PDN.Lydo + "',tungay='";
            sql += PDN.Tungay + "',denngay='";
            sql += PDN.Denngay + "' where sophieu='";
            sql += PDN.Sophieu + "'";
            cmd = new SqlCommand();
            cmd.CommandText = sql;
            int rs = conn.Executive(cmd);
            if (rs <= 0)
                error = conn.Error;
        }
       // re
    }
}
